import os,sys,time
import datetime as dt
import shutil


dir=r'd:\11'

def removeDirs(dirpath:str)->int:
    ret=0
    os.chdir(dirpath)
    fns=os.listdir()
    if len(fns)>1:
        fns=fns[0:-1]
    try:
        for i in fns:
            currdir=f'{dirpath}\\{i}'
            # os.removedirs(currdir)
            shutil.rmtree(currdir)
            ret+=1
    except Exception as ex:
        print(str(ex))
        pass
    return ret



if __name__ == "__main__":
    while True:
        t1=dt.datetime.now()
        # x=removeDirs(sys.argv[1])
        x=removeDirs(dir)
        print(f'[{t1}] 删除{x}条目录')
        time.sleep(200)

    pass
